﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="meerikParing", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(MeerikParing))]
    public class MeerikParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMeerikParing clazz;
        
        public MeerikParingSerializer(IMeerikParing clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("kaart_nr");
            if (clazz.KaartNr!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KaartNr))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KaartNr");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("valdaja_iskukood");
            if (clazz.ValdajaIskukood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ValdajaIskukood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ValdajaIskukood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("valdaja_eesnimi");
            if (clazz.ValdajaEesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ValdajaEesnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ValdajaEesnimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("valdaja_perenimi");
            if (clazz.ValdajaPerenimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ValdajaPerenimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ValdajaPerenimi");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="kaart_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>meerikParing>kaart_nr");
                }
                clazz.KaartNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kaart_nr")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>meerikParing>kaart_nr", Reader.LocalName);
            }
            if (Reader.LocalName=="valdaja_iskukood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>meerikParing>valdaja_iskukood");
                }
                clazz.ValdajaIskukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("valdaja_iskukood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>meerikParing>valdaja_iskukood", Reader.LocalName);
            }
            if (Reader.LocalName=="valdaja_eesnimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>meerikParing>valdaja_eesnimi");
                }
                clazz.ValdajaEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("valdaja_eesnimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>meerikParing>valdaja_eesnimi", Reader.LocalName);
            }
            if (Reader.LocalName=="valdaja_perenimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>meerikParing>valdaja_perenimi");
                }
                clazz.ValdajaPerenimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("valdaja_perenimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>meerikParing>valdaja_perenimi", Reader.LocalName);
            }
        }
    }
}
